﻿using System.Web.Mvc;
using eCRAM.Model;
using eCRAM.WebSite.Attributes;
using eCRAM.WebSite.Models;
using eCRAM.WebSite.Tools;
using eCRAM.Dao;

namespace eCRAM.WebSite.Controllers
{
    [CustomAuthorization(UserRole.ProjectLeader, UserRole.Administrator)]
    public class ProjectResumeController : Controller
    {
        //
        // GET: /ProjectResume/

        public ActionResult Index()
        {
            return RedirectToAction("SearchActivity", new SearchMetricsModel());
        }

        /// <summary>
        /// Affiche le formulaire de recherche
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult SearchActivity(SearchMetricsModel model)
        {
            return View("SearchMetrics", model);
        }


        /// <summary>
        /// Effectue la recherche
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Search(SearchMetricsModel model)
        {
            var result = ActivityRepository.GetById(model.Criterias.ActivityId);
            model.Results = SearchActivityResultsModel.FromActivity(result);

            return View("SearchMetrics", model);
        }

    }
}
